package com.elai.baseconfig.controller;

import java.util.List;

import com.elai.baseconfig.service.EventTeamService;
import com.elai.common.core.domain.entity.SysUser;
import com.elai.common.utils.SecurityUtils;
import com.elai.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.enums.BusinessType;
import com.elai.baseconfig.domain.BaseLesseeInfo;
import com.elai.baseconfig.service.IBaseLesseeInfoService;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.common.core.page.TableDataInfo;

/**
 * 租户信息Controller
 *
 * @author elai
 * @date 2022-04-09
 */
@RestController
@RequestMapping("/baseconfig/lessee")
public class BaseLesseeInfoController extends BaseController
{
    @Autowired
    private IBaseLesseeInfoService baseLesseeInfoService;






    /**
     * 查询租户信息列表
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:lessee:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseLesseeInfo baseLesseeInfo)
    {
        startPage();
        List<BaseLesseeInfo> list = baseLesseeInfoService.selectBaseLesseeInfoList(baseLesseeInfo);
        return getDataTable(list);
    }

    /**
     * 导出租户信息列表
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:lessee:export')")
    @Log(title = "租户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseLesseeInfo baseLesseeInfo)
    {
        List<BaseLesseeInfo> list = baseLesseeInfoService.selectBaseLesseeInfoList(baseLesseeInfo);
        ExcelUtil<BaseLesseeInfo> util = new ExcelUtil<BaseLesseeInfo>(BaseLesseeInfo.class);
        return util.exportExcel(list, "租户信息数据");
    }

    /**
     * 获取租户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:lessee:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseLesseeInfoService.selectBaseLesseeInfoById(id));
    }

    @GetMapping(value = "/getCurrentLessee")
    public AjaxResult getCurrentLessee()
    {
        SysUser currentUser= SecurityUtils.getLoginUser().getUser();
        BaseLesseeInfo lesseeInfo =null;
        if(StringUtils.isNotEmpty(currentUser.getLesseeId())) {
            lesseeInfo = baseLesseeInfoService.selectBaseLesseeInfoByLesseeId(currentUser.getLesseeId());
        }
        return AjaxResult.success(lesseeInfo);
    }

    /**
     * 新增租户信息
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:lessee:add')")
    @Log(title = "租户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseLesseeInfo baseLesseeInfo)
    {
        return toAjax(baseLesseeInfoService.insertBaseLesseeInfo(baseLesseeInfo));
    }

    /**
     * 修改租户信息
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:lessee:edit')")
    @Log(title = "租户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseLesseeInfo baseLesseeInfo)
    {
        return toAjax(baseLesseeInfoService.updateBaseLesseeInfo(baseLesseeInfo));
    }

    /**
     * 删除租户信息
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:lessee:remove')")
    @Log(title = "租户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseLesseeInfoService.deleteBaseLesseeInfoByIds(ids));
    }
}
